﻿using System;
using Microsoft.Practices.Unity;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace TestByWire.Test
{
    [TestClass]
    public class ThenTests
    {
        private IUnityContainer _container;

        [TestInitialize]
        public void Init()
        {
            _container = new UnityContainer();
            Then.Reset(_container);
        }

        [TestMethod]
        public void Should()
        {
            var stub = MockRepository.GenerateStub<IDbAccess>();
            _container.RegisterInstance(stub);

            stub.GetCurrentSalary("Foo");

            Then<IDbAccess>.Should(x => x.GetCurrentSalary("Foo"));
        }

        [TestMethod]
        public void ShouldNot()
        {
            var stub = MockRepository.GenerateStub<IDbAccess>();
            _container.RegisterInstance(stub);

            stub.GetCurrentSalary("Bar");

            Then<IDbAccess>.ShouldNot(x => x.GetCurrentSalary("Foo"));
        }

        [TestMethod]
        public void ThrowsException()
        {
            var expectedException = new ArgumentException();
            var exception = new Then().TargetShouldThrow<ArgumentException>(()=>FaillingMethod(expectedException));

            Assert.AreEqual(expectedException, exception);
        }

        private static void FaillingMethod(Exception exceptionToThrow)
        {
            throw exceptionToThrow;
        }
    }
}
